package com.cfpamf.ms.insur.pay.controller;

import com.cfpamf.common.ms.result.Result;
import com.cfpamf.common.ms.template.MSOperateCallback;
import com.cfpamf.common.ms.template.MSTemplate;
import com.cfpamf.ms.insur.pay.aspect.annotation.RequestRecordLog;
import com.cfpamf.ms.insur.pay.facade.dto.PayOrderDTO;
import com.cfpamf.ms.insur.pay.facade.dto.PreCreateOrderDTO;
import com.cfpamf.ms.insur.pay.facade.dto.QueryOrderDTO;
import com.cfpamf.ms.insur.pay.facade.dto.RefundOrderDTO;
import com.cfpamf.ms.insur.pay.facade.vo.PayOrderVO;
import com.cfpamf.ms.insur.pay.facade.vo.PreCreateOrderVO;
import com.cfpamf.ms.insur.pay.facade.vo.QueryOrderVO;
import com.cfpamf.ms.insur.pay.facade.vo.RefundOrderVO;
import com.cfpamf.ms.insur.pay.service.InsurPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 保险请求支付接口
 *
 * @author zhangnayi
 */
@Slf4j
@Api(value = "保险请求支付接口", tags = {"保险请求支付接口"})
@RequestMapping("/insurPay")
@RestController
public class InsurPayController {

    /**
     * 保险支付service
     */
    @Autowired
    private InsurPayService insurPayService;

    /**
     * 预下单接口
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "预下单接口")
    @PostMapping("/preCreateOrder")
    @RequestRecordLog
    public Result<PreCreateOrderVO> preCreateOrder(@RequestBody @Validated PreCreateOrderDTO params) {
        return MSTemplate.operate(new MSOperateCallback<PreCreateOrderVO>() {
            @Override
            public void checkParams() {
            }

            @Override
            public PreCreateOrderVO doOperate() {
                return insurPayService.preCreateOrder(params);
            }
        });
    }

    /**
     * 订单支付接口
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "订单支付接口")
    @PostMapping("/payOrder")
    public Result<PayOrderVO> payOrder(@RequestBody @Validated PayOrderDTO params) {
        return MSTemplate.operate(new MSOperateCallback<PayOrderVO>() {
            @Override
            public void checkParams() {
            }

            @Override
            public PayOrderVO doOperate() {
                return insurPayService.payOrder(params);
            }
        });
    }

    /**
     * 订单查询接口
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "订单查询接口")
    @PostMapping("/queryOrderInfo")
    public Result<QueryOrderVO> queryOrderInfo(@RequestBody @Validated QueryOrderDTO params) {
        return MSTemplate.operate(new MSOperateCallback<QueryOrderVO>() {
            @Override
            public void checkParams() {
            }

            @Override
            public QueryOrderVO doOperate() {
                return insurPayService.queryOrderInfo(params);
            }
        });
    }

    /**
     * 订单退款接口
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "订单退款接口")
    @PostMapping("/refundOrder")
    public Result<RefundOrderVO> refundOrder(@RequestBody @Validated RefundOrderDTO params) {
        return MSTemplate.operate(new MSOperateCallback<RefundOrderVO>() {
            @Override
            public void checkParams() {
            }

            @Override
            public RefundOrderVO doOperate() {
                return insurPayService.refundOrder(params);
            }
        });
    }
}
